Ext.define('SKJF.view.PEMBELIAN.v_terimabarang_form', {
	extend	: 'Ext.form.Panel',
	
	alias	: 'widget.v_terimabarang_form',
	
	//region:'east',
	//id: 'east-region-container',
	
	title		: 'Create/Update terimabarang',
    bodyPadding	: 5,
    autoScroll	: true,
    
    initComponent: function(){
    	/*
		 * Deklarasi variable setiap field
		 */
		
		var po_store = Ext.create('SKJF.store.s_po');
		po_store.load();
		var mstsupp_store = Ext.create('SKJF.store.s_mstsupplier');
		var lpb_store = Ext.create('Ext.data.Store', {
			fields: ['value', 'display'],
			data : [
				{"value":"IDR", "display":"IDR"},
				{"value":"VALAS", "display":"VALAS"},
				{"value":"IMPORT", "display":"IMPORT"}
			]
		});
		
		var status_store = Ext.create('Ext.data.Store', {
			fields: ['value', 'display'],
			data : [
				{"value":"BELUM", "display":"BELUM"},
				{"value":"CICIL", "display":"CICIL"},
				{"value":"LUNAS", "display":"LUNAS"}
			]
		});
		
		var APA_KAPSUL_store = Ext.create('Ext.data.Store', {
			fields: ['value', 'display'],
			data : [{"value":"1", "display":"YA"},{"value":"0", "display":"TIDAK"}]
		});
		
		var NOMOR_LPB_field = Ext.create('Ext.form.field.Text', {
			itemId: 'NOMOR_LPB_field',
			name: 'NOMOR_LPB', /* column name of table */
			fieldLabel: 'NOMOR_LPB',
			maxLength: 25 /* length of column name */
		});
		var TANGGAL_LPB_field = Ext.create('Ext.form.field.Date', {
			name: 'TANGGAL_LPB', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TANGGAL_LPB',
			value: new Date()
		});
		var NOMOR_PO_field = Ext.create('Ext.form.field.ComboBox', {
			itemId: 'NOMOR_PO_field',
			name: 'NOMOR_PO', /* column name of table */
			fieldLabel: 'NOMOR_PO',
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: po_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{NOMOR_PO} - {NAMA_SUPPLIER}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{NOMOR_PO} - {NAMA_SUPPLIER}',
				'</tpl>'
			),
			valueField: 'NOMOR_PO',
			displayField: 'NOMOR_PO',
			enableKeyEvents: true,
			listeners: {
				select: function(combo, records, e){
					var ns = records[0].data.NAMA_SUPPLIER;
					mstsupp_store.clearFilter(true);
					mstsupp_store.filter('NAMA_SUPPLIER',ns);
					mstsupp_store.load();
				}
			}
		});
		var NAMA_SUPPLIER_field = Ext.create('Ext.form.field.Text', {
			name: 'NAMA_SUPPLIER', /* column name of table */
			fieldLabel: 'NAMA_SUPPLIER',
			readOnly: true
		});
		var KODE_SUPPLIER_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'KODE_SUPPLIER', /* column name of table */
			fieldLabel: 'KODE_SUPPLIER',
			pageSize: 10,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: mstsupp_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{KODE_SUPPLIER} - {NAMA_SUPPLIER}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{KODE_SUPPLIER} - {NAMA_SUPPLIER}',
				'</tpl>'
			),
			valueField: 'KODE_SUPPLIER',
			displayField: 'KODE_SUPPLIER',
			enableKeyEvents: true,
			listeners: {
				select: function(combo, records, e){
					var ns = records[0].data.NAMA_SUPPLIER;
					NAMA_SUPPLIER_field.setValue(ns);
				}
			}
		});
		var APA_KAPSUL_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'APA_KAPSUL', /* column name of table */
			fieldLabel: 'APA_KAPSUL',
			store: APA_KAPSUL_store,
			queryMode: 'local',
			displayField: 'display',
			valueField: 'value'
		});
		var JENIS_LPB_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'JENIS_LPB', /* column name of table */
			fieldLabel: 'JENIS_LPB',
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: lpb_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{display}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{display}',
				'</tpl>'
			),
			valueField: 'value',
			displayField: 'display'
		});
		var NOMOR_INVOICE_field = Ext.create('Ext.form.field.Text', {
			name: 'NOMOR_INVOICE', /* column name of table */
			fieldLabel: 'NOMOR_INVOICE',
			maxLength: 100 /* length of column name */
		});
		var TANGGAL_INVOICE_field = Ext.create('Ext.form.field.Date', {
			name: 'TANGGAL_INVOICE', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TANGGAL_INVOICE'
		});
		var NOMOR_PIB_field = Ext.create('Ext.form.field.Text', {
			name: 'NOMOR_PIB', /* column name of table */
			fieldLabel: 'NOMOR_PIB',
			maxLength: 25 /* length of column name */
		});
		var TANGGAL_PIB_field = Ext.create('Ext.form.field.Date', {
			name: 'TANGGAL_PIB', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TANGGAL_PIB'
		});
		var NOMOR_FAKTUR_field = Ext.create('Ext.form.field.Text', {
			name: 'NOMOR_FAKTUR', /* column name of table */
			fieldLabel: 'NOMOR_FAKTUR',
			maxLength: 25 /* length of column name */
		});
		var TANGGAL_FAKTUR_field = Ext.create('Ext.form.field.Date', {
			name: 'TANGGAL_FAKTUR', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TANGGAL_FAKTUR'
		});
		var JATUH_TEMPO_field = Ext.create('Ext.form.field.Date', {
			name: 'JATUH_TEMPO', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'JATUH_TEMPO'
		});
		var CURRENCY_field = Ext.create('Ext.form.field.Text', {
			name: 'CURRENCY', /* column name of table */
			fieldLabel: 'CURRENCY',
			maxLength: 3 /* length of column name */
		});
		var KURS_field = Ext.create('Ext.form.field.Number', {
			name: 'KURS', /* column name of table */
			fieldLabel: 'KURS',
			maxLength: 11 /* length of column name */
		});
		var SUB_TOTAL_field = Ext.create('Ext.form.field.Number', {
			name: 'SUB_TOTAL', /* column name of table */
			fieldLabel: 'SUB_TOTAL',
			readOnly: true
		});
		var PPN_field = Ext.create('Ext.form.field.Text', {
			name: 'PPN', /* column name of table */
			fieldLabel: 'PPN',
			value: '10%',
			readOnly: true
		});
		var TOTAL_field = Ext.create('Ext.form.field.Number', {
			name: 'TOTAL', /* column name of table */
			fieldLabel: 'TOTAL',
			readOnly: true
		});
		var MATERAI_field = Ext.create('Ext.form.field.Number', {
			name: 'MATERAI', /* column name of table */
			fieldLabel: 'MATERAI',
			readOnly: true,
		});
		var DIBUAT_OLEH_field = Ext.create('Ext.form.field.Text', {
			name: 'DIBUAT_OLEH', /* column name of table */
			fieldLabel: 'DIBUAT_OLEH',
			value: username,
			readOnly: true
		});
		var JUMLAH_EDIT_field = Ext.create('Ext.form.field.Number', {
			name: 'JUMLAH_EDIT', /* column name of table */
			fieldLabel: 'JUMLAH_EDIT',
			readOnly: true
		});
		var TANGGAL_EDIT_field = Ext.create('Ext.form.field.Date', {
			name: 'TANGGAL_EDIT', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TANGGAL_EDIT',
			value: new Date(),
			readOnly: true
		});
		var STATUS_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'STATUS', /* column name of table */
			fieldLabel: 'STATUS',
			allowBlank: false,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: status_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{display}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{display}',
				'</tpl>'
			),
			valueField: 'value',
			displayField: 'display',
			value: 'BELUM'
		});
        Ext.apply(this, {
            fieldDefaults: {
                labelAlign: 'right',
                labelWidth: 120,
                msgTarget: 'qtip',
				anchor: '100%'
            },
			defaultType: 'textfield',
            items: [NOMOR_LPB_field,{xtype:'container',layout:{type:'hbox'},items:[TANGGAL_LPB_field,JENIS_LPB_field,APA_KAPSUL_field]},NOMOR_PO_field,KODE_SUPPLIER_field,NAMA_SUPPLIER_field,NOMOR_INVOICE_field,TANGGAL_INVOICE_field,NOMOR_PIB_field,TANGGAL_PIB_field,NOMOR_FAKTUR_field,TANGGAL_FAKTUR_field,JATUH_TEMPO_field,CURRENCY_field,KURS_field,SUB_TOTAL_field,PPN_field,MATERAI_field,TOTAL_field,DIBUAT_OLEH_field,JUMLAH_EDIT_field,TANGGAL_EDIT_field,STATUS_field],
			
	        buttons: [{
                iconCls: 'icon-save',
                itemId: 'save',
                text: 'Save',
                disabled: true,
                action: 'save'
            }, {
                iconCls: 'icon-add',
				itemId: 'create',
                text: 'Create',
                action: 'create'
            }, {
                iconCls: 'icon-reset',
                text: 'Cancel',
                action: 'cancel'
            }]
        });
        
        this.callParent();
    }
});